#include "Material.hpp"

namespace gl
{

Material::Material()
{
	diffuse[0]	= 0.8f;	diffuse[1]	= 0.8f;	diffuse[2]	= 0.8f;	diffuse[3]	= 1.0f;
	ambient[0]	= 0.2f;	ambient[1]	= 0.2f;	ambient[2]	= 0.2f;	ambient[3]	= 1.0f;
	specular[0] = 0.0f; specular[1] = 0.0f; specular[2] = 0.0f; specular[3] = 1.0f;
	emissive[0] = 0.0f; emissive[1] = 0.0f; emissive[2] = 0.0f; emissive[3]	= 1.0f;
	shininess = 0.0f;
	texCount = 0;
}

Material::Material(aiMaterial *mtl, int texCount)
{
	diffuse[0]	= 0.8f;	diffuse[1]	= 0.8f;	diffuse[2]	= 0.8f;	diffuse[3]	= 1.0f;
	ambient[0]	= 0.2f;	ambient[1]	= 0.2f;	ambient[2]	= 0.2f;	ambient[3]	= 1.0f;
	specular[0] = 0.0f; specular[1] = 0.0f; specular[2] = 0.0f; specular[3] = 1.0f;
	emissive[0] = 0.0f; emissive[1] = 0.0f; emissive[2] = 0.0f; emissive[3]	= 1.0f;
	shininess = 0.0f;
	this->texCount = texCount;

	aiColor4D aiDiffuse;
	if(aiGetMaterialColor(mtl, AI_MATKEY_COLOR_DIFFUSE, &aiDiffuse) == AI_SUCCESS)
		memcpy(diffuse, &aiDiffuse, sizeof(aiDiffuse));

	aiColor4D aiAmbient;
	if(aiGetMaterialColor(mtl, AI_MATKEY_COLOR_AMBIENT, &aiAmbient) == AI_SUCCESS)
		memcpy(ambient, &aiAmbient, sizeof(aiAmbient));

	aiColor4D aiSpecular;
	if(aiGetMaterialColor(mtl, AI_MATKEY_COLOR_SPECULAR, &aiSpecular) == AI_SUCCESS)
		memcpy(specular, &aiSpecular, sizeof(aiSpecular));

	aiColor4D aiEmission;
	if(aiGetMaterialColor(mtl, AI_MATKEY_COLOR_EMISSIVE, &aiEmission) == AI_SUCCESS)
		memcpy(emissive, &aiEmission, sizeof(aiEmission));

	float aiShininess = 0.0f;
	unsigned int max;
	if(aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS, &shininess, &max) == AI_SUCCESS)
		shininess = aiShininess;
}

}